﻿function muestramenu() {
    document.getElementById("divMenu").style.display = "none";
    document.getElementById("divMenuContent").style.display = "";
}

function ocultamenu() {
    document.getElementById("divMenu").style.display = "";
    document.getElementById("divMenuContent").style.display = "none";
}

function OpenLogin() {
//    var navegador_valido = true;
//    if (navigator.appName == "Netscape") {
//        if (navigator.userAgent.indexOf("Chrome") > 0 || navigator.vendor == "Google Inc.") {
//            navegador_valido = false;
//        }
//    }

//    if (navegador_valido) {
//        if (document.getElementById("login").style.display == "block") {
//            document.getElementById("login").style.display = "none";
//        }
//        else {
//            //document.getElementById("flashContent").style.display = "none";
//            document.getElementById("login").style.display = "block";
//            //document.getElementById("flashContent").style.display = "block";
//            $get(txtUsuario + "_TxtControl").focus();
//        }
//    }
//    else {
//        alert("Se ha detectado que esta usando el navegador Chrome, favor de iniciar sesión en Internet Explorer o FireFox u otro navegador soportado.");
//    }
    if (document.getElementById("login").style.display == "block" || document.getElementById("login").style.display == "") {
        document.getElementById("login").style.display = "none";
    }
    else {
        document.getElementById("asistencia").style.display = "none";
        var u = $get(txtUsuario + "_TxtControl");
        var p = $get(txtPassword + "_TxtControl");
        u.style.backgroundColor = "";
        u.style.border = "";
        p.style.backgroundColor = "";
        p.style.border = "";
        document.getElementById("login").style.display = "";
        $get(txtUsuario + "_TxtControl").focus();
    }

    if (document.getElementById(hdnDia).value == "0") {
        if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
            document.getElementById('DiasHoy').style.display = "";
        else
            document.getElementById('DiasHoy').style.display = "none";
    }
    else {
        if (parseInt(document.getElementById(hdnDia).value) > 0) {
            if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
                document.getElementById('Dias').style.display = "";
            else
                document.getElementById('Dias').style.display = "none";
        }
    }

    return false;
}

function AceptarLogin() {
    var u = $get(txtUsuario + "_TxtControl");
    var p = $get(txtPassword + "_TxtControl");
    u.style.backgroundColor = "";
    u.style.border = "";
    p.style.backgroundColor = "";
    p.style.border = "";
    if (u.value.trim() != "" && p.value.trim() != "") {
        var id = $get(hdnIdInvitacion).value;
        PageMethods.ValidaUsuario(id, u.value.trim(), p.value.trim(), OnSucceeded, OnFailed);
    }
    else {
        alert("Faltan campos requeridos");
        if (u.value.trim() == "") {
            u.style.backgroundColor = "#FFF4F4";
            u.style.border = "solid 1px red";
            u.focus();
        }
        if (p.value.trim() == "") {
            p.style.backgroundColor = "#FFF4F4";
            p.style.border = "solid 1px red";
            p.focus();
        }
    }
    return false;
}

function OpenConfirmar() {
    if (document.getElementById("asistencia").style.display == "") {
        document.getElementById("asistencia").style.display = "none";
    }
    else {
        document.getElementById("login").style.display = "none";
        var txt_nom = $get(txtNombre + "_TxtControl");
        txt_nom.style.backgroundColor = "";
        txt_nom.style.border = "";
        document.getElementById("asistencia").style.display = "";
        $get(txtNombre + "_TxtControl").focus();
    }

    if (document.getElementById(hdnDia).value == "0") {
        if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
            document.getElementById('DiasHoy').style.display = "";
        else
            document.getElementById('DiasHoy').style.display = "none";
    }
    else {
        if (parseInt(document.getElementById(hdnDia).value) > 0) {
            if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
                document.getElementById('Dias').style.display = "";
            else
                document.getElementById('Dias').style.display = "none";
        }
    }

    return false;
}

function OnSucceeded(valor) {
    if (valor) {
        document.getElementById("login").style.display = "none";
        $get(txtUsuario + "_TxtControl").value = "";
        $get(txtPassword + "_TxtControl").value = "";
        validaBarra();
    }
    else {
        alert("Nombre de Usuario o Contraseña invalido");
    }
}

function OnFailed(error) {
    alert(error.get_message());
}

function validaBarra() {
    PageMethods.ValidaBarra(OnSucceededBarra, OnFailed);
}

function OnSucceededBarra(valor) {
    $get(BtnLogout).style.display = "none";
    $get(LblUsuario).innerHTML = "[Invitado]";
    $get(BtnLogin).style.display = "";
    document.getElementById(LnkLista).style.display = "none";
    document.getElementById("login").style.display = "none";
    document.getElementById("asistencia").style.display = "none";
    if (valor != "") {
        $get(BtnLogin).style.display = "none";
        $get(BtnLogout).style.display = "";
        document.getElementById(LnkLista).style.display = "";
        document.getElementById("login").style.display = "none";
        $get(LblUsuario).innerHTML = valor;
    }

    if (document.getElementById(hdnDia).value == "0") {
        if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
            document.getElementById('DiasHoy').style.display = "";
        else
            document.getElementById('DiasHoy').style.display = "none";
    }
    else {
        if (parseInt(document.getElementById(hdnDia).value) > 0) {
            if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
                document.getElementById('Dias').style.display = "";
            else
                document.getElementById('Dias').style.display = "none";
        }
    }
}

function pageLoad(sender, args)
{
    validaBarra();
    muestramenu();
    //document.getElementById("login").style.display = "none";
    if (window.contentPageLoad) {
        window.contentPageLoad(sender, args);
    }
}

document.onkeydown = function () {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox      

    return (key != 13);
}

function ExitLogin() {
    PageMethods.Logout(OnSucceededLogout, OnFailed);
    return false;
}

function OnSucceededLogout() {
    validaBarra();
}

function loginkeypress(e) {
    if (e.keyCode.toString() == "13") {
        AceptarLogin();
    }
}

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox      

    return (key != 13);
}

function EnviarConfirmacion() {
    var id = $get(hdnIdInvitacion).value;
    var nom = $get(txtNombre + "_TxtControl").value.trim();
    var txt_nom = $get(txtNombre + "_TxtControl");
    txt_nom.style.backgroundColor = "";
    txt_nom.style.border = "";
    var numAdultos = $get(txtNumAdultos + "_TxtControl").value;
    var numNinos = 0;
    if (typeof(txtNumNinos) !='undefined')
    {
        if (txtNumNinos != null )
            if ($get(txtNumNinos + "_TxtControl") != null)
                numNinos = $get(txtNumNinos + "_TxtControl").value;
    }

    var com = $get(txtCom + "_TxtControl").value;
    if (nom != "") {
        if (numAdultos.toString().trim() == "")
            numAdultos = "0";
        if (numNinos.toString().trim() == "")
            numNinos = "0";
        PageMethods.InsertaConfirmacion(id, nom, numAdultos, numNinos, com.toString().trim(), OnSucceededConfirma, OnFailed);
    }
    else {
        alert("Escriba su Nombre o Familia a confirmar");
        txt_nom.style.backgroundColor = "#FFF4F4";
        txt_nom.style.border = "solid 1px red";
        txt_nom.focus();
    }
    return false;
}

function OnSucceededConfirma() {
    $get(txtNombre + "_TxtControl").value = "";
    $get(txtNumAdultos + "_TxtControl").value = "";
    if (typeof (txtNumNinos) != 'undefined') {
        if (txtNumNinos != null)
            if ($get(txtNumNinos + "_TxtControl") != null)
                $get(txtNumNinos + "_TxtControl").value = "";
    }
    $get(txtCom + "_TxtControl").value = "";
    document.getElementById("asistencia").style.display = "none";
    alert("Se ha confirmado tu asistencia");

    if (document.getElementById(hdnDia).value == "0") {
        if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
            document.getElementById('DiasHoy').style.display = "";
        else
            document.getElementById('DiasHoy').style.display = "none";
    }
    else {
        if (parseInt(document.getElementById(hdnDia).value) > 0) {
            if (document.getElementById("login").style.display == "none" && document.getElementById("asistencia").style.display == "none")
                document.getElementById('Dias').style.display = "";
            else
                document.getElementById('Dias').style.display = "none";
        }
    }
}

function ConsultaAsistencia() {
    if ($get(LblUsuario).innerHTML != "[Invitado]")
    {
        var id = $get(hdnIdInvitacion).value;
        var a = document.createElement('a');
        a.href = 'http://ganda-invitaciones.com/ConsultaAsistencia.aspx?IdInvitacion=' + id.toString();
        a.target = '_blank';
		if (navigator.appName == "Netscape" && navigator.userAgent.indexOf("Safari") > 0 && navigator.vendor == "Apple Computer, Inc.") {
            window.location = a.href;
		}
		else
		{
			document.body.appendChild(a);
			a.click();
		}
    }

    return false;
}